#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QObject::connect(ui->pushButton_mini, SIGNAL(clicked(bool)), this, SLOT(showMinimized()));

    QObject::connect(ui->pushButton_custom, SIGNAL(clicked(bool)), this, SLOT(slotTest(bool)));

    //连接自定义信号和槽
    QObject::connect(this, SIGNAL(sigTest(int)), this, SLOT(slotSig(int)));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slotTest(bool bl)
{
    qDebug() << "我是自定义槽"  << bl;
}

void MainWindow::on_pushButton_auto_clicked(bool bl)
{
    qDebug() << "我是自定义的自动连接槽" << bl;
}

void MainWindow::slotSig(int n)
{
    qDebug() << "我连接了自定义信号"  << n;
}

void MainWindow::on_pushButton_clicked(bool checked)
{
    qDebug() << "我是自定义的快速自动连接槽";
}

void MainWindow::on_pushButton_2_clicked()
{
    //发射自定义信号
    emit sigTest(888);
}

void MainWindow::on_pushButton_3_clicked()
{
    QObject::disconnect(this, SIGNAL(sigTest(int)), this, SLOT(slotSig(int)));
    qDebug() << "连接已断开";
}

void MainWindow::on_pushButton_4_clicked()
{
    //连接自定义信号和槽
    QObject::connect(this, SIGNAL(sigTest(int)), this, SLOT(slotSig(int)));
    qDebug() << "连接已恢复";

}
